import java.awt.Graphics;

import me.w70.bot.scripting.Random;
import me.w70.bot.wrappers.RSInterfaces;


public class InterfaceCloser extends Random {

	@Override
	public boolean canRun() {
		if (!isLoggedIn()) {
			return false;
		}
		if (RSInterfaces.getInterface(755).getChild(3).isValid()){ //World map
			return true;
		}
		if (RSInterfaces.getInterface(743).getChild(20).isValid()){ //Audio
			return true;
		}
		if (RSInterfaces.getInterface(767).getChild(10).isValid()){ //Bank Help
			return true;
		}
		if (RSInterfaces.getInterface(499).getChild(29).isValid()){ //Stats
			return true;
		}
		if (RSInterfaces.getInterface(594).getChild(48).isValid()){ //Report
			return true;
		}
		if (RSInterfaces.getInterface(742).getChild(25).isValid()){ //Graphics
			return true;
		}
		if (RSInterfaces.getInterface(275).getChild(8).isValid()){ //Quest
			return true;
		}
		if (RSInterfaces.getInterface(206).getChild(16).isValid()){ //Price Check
			return true;
		}
		if (RSInterfaces.getInterface(266).getChild(11).isValid()){ //Grave
			return true;
		}
		if (RSInterfaces.getInterface(109).getChild(13).isValid()){ //GE Collection Box
			return true;
		}
		if (RSInterfaces.getInterface(102).getChild(13).isValid()){ //Death items
			return true;
		}
		if (RSInterfaces.getInterface(590).getChild(3).isValid()){ //Clan Setup
			return true;
		}
		if (RSInterfaces.getInterface(14).getChild(3).isValid()){ //PIN settings
			return true;
		}

		return false;
	}

	@Override
	public String getScriptAuthor() {
		return "spooky";
	}

	@Override
	public String getScriptName() {
		return "Interface Closer";
	}



	@Override
	public int loop() {
		if (RSInterfaces.getInterface(755).isValid()) {
			atInterface(RSInterfaces.getInterface(755).getChild(3)); //World map
			return random(500, 900);
		}

		if (RSInterfaces.getInterface(743).isValid()) {
			atInterface(RSInterfaces.getInterface(743).getChild(20)); //Audio
			wait(random(500,900));
		}
		if (RSInterfaces.getInterface(767).isValid()) {
			atInterface(RSInterfaces.getInterface(767).getChild(10)); //Bank Help
			wait(random(500,900));
		}
		if (RSInterfaces.getInterface(499).isValid()) {
			atInterface(RSInterfaces.getInterface(499).getChild(29)); //Stats
			wait(random(500,900));
		}
		if (RSInterfaces.getInterface(594).isValid()) {
			atInterface(RSInterfaces.getInterface(594).getChild(48)); //Report
			wait(random(500,900));
		}
		if (RSInterfaces.getInterface(742).isValid()) {
			atInterface(RSInterfaces.getInterface(742).getChild(25)); //Graphics
			wait(random(500,900));
		}
		if (RSInterfaces.getInterface(275).isValid()) {
			atInterface(RSInterfaces.getInterface(275).getChild(8)); //Quest
			wait(random(500,900));
		}
		if (RSInterfaces.getInterface(206).isValid()) {
			atInterface(RSInterfaces.getInterface(206).getChild(16)); //Price Check
			wait(random(500,900));
		}
		if (RSInterfaces.getInterface(266).isValid()) {
			atInterface(RSInterfaces.getInterface(266).getChild(11)); //Grave
			wait(random(500,900));
		}
		if (RSInterfaces.getInterface(109).isValid()) {
			atInterface(RSInterfaces.getInterface(109).getChild(13));  //GE Collection Box
			wait(random(500,900));
		}
		if (RSInterfaces.getInterface(102).isValid()) {
			atInterface(RSInterfaces.getInterface(102).getChild(13)); //Death items
			wait(random(500,900));
		}
		if (RSInterfaces.getInterface(590).isValid()) {
			atInterface(RSInterfaces.getInterface(590).getChild(3)); //Clan Setup
			wait(random(500,900));
		}
		if (RSInterfaces.getInterface(14).isValid()) {
			atInterface(RSInterfaces.getInterface(14).getChild(3)); //PIN settings
			wait(random(500, 900));
		}

		return -1;
	}

	@Override
	public void draw(Graphics g) {
		// TODO Auto-generated method stub
	}

	@Override
	public String getScriptCategory() {
		// TODO Auto-generated method stub
		return "Random";
	}

	@Override
	public String getScriptDescription() {
		// TODO Auto-generated method stub
		return "Closes all open interfaces";
	}
}